package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Coach;
import com.ruoyi.system.service.ICoachService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教练列表Controller
 * 
 * @author ruoyi
 * @date 2022-11-28
 */
@RestController
@RequestMapping("/system/coach")
public class CoachController extends BaseController
{
    @Autowired
    private ICoachService coachService;

    /**
     * 查询教练列表列表
     */
    @PreAuthorize("@ss.hasPermi('system:coach:list')")
    @GetMapping("/list")
    public TableDataInfo list(Coach coach)
    {
        startPage();
        List<Coach> list = coachService.selectCoachList(coach);
        return getDataTable(list);
    }

    /**
     * 导出教练列表列表
     */
    @PreAuthorize("@ss.hasPermi('system:coach:export')")
    @Log(title = "教练列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Coach coach)
    {
        List<Coach> list = coachService.selectCoachList(coach);
        ExcelUtil<Coach> util = new ExcelUtil<Coach>(Coach.class);
        util.exportExcel(response, list, "教练列表数据");
    }

    /**
     * 获取教练列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:coach:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(coachService.selectCoachById(id));
    }

    /**
     * 新增教练列表
     */
    @PreAuthorize("@ss.hasPermi('system:coach:add')")
    @Log(title = "教练列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Coach coach)
    {
        return toAjax(coachService.insertCoach(coach));
    }

    /**
     * 修改教练列表
     */
    @PreAuthorize("@ss.hasPermi('system:coach:edit')")
    @Log(title = "教练列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Coach coach)
    {
        return toAjax(coachService.updateCoach(coach));
    }

    /**
     * 删除教练列表
     */
    @PreAuthorize("@ss.hasPermi('system:coach:remove')")
    @Log(title = "教练列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(coachService.deleteCoachByIds(ids));
    }
}
